package com.shengqi.proxy_hook.hook.activityhook;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;

public class EvilResource extends Resources {
    private static final String TAG = "EvilResource";
    private Resources resources;

    public EvilResource(Resources resources) {
        super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
        this.resources = resources;
    }

    public CharSequence getText(int id) throws NotFoundException {
        Log.e(TAG, "get in getText name = " + getResourceName(id));

        CharSequence res = "XXXXXXXXXXXXXX";//getResourceName(id);
        if (res != null) {
            return res;
        }
        //TODO： 添加动态代理
        return resources.getText(id);
    }


    public String[] getStringArray(int id)
            throws NotFoundException {
        Log.e(TAG, "get in getStringArray name = " + getResourceName(id));
        if (LanguageManager.stringArrayHashMap != null)
            Log.e(TAG, "get in getStringArray value = " + getResourceName(id).split("/")[1]);
        if (LanguageManager.stringArrayHashMap != null) {
            Log.e(TAG, "get in getStringArray value = " + LanguageManager.stringArrayHashMap.get(getResourceName(id).split("/")[1])[0]);
        }
        String[] res = {
                "XXXXX",
                "YYYYY"
        };

        if (res != null) {
            return res;
        }

        return resources.getStringArray(id);
    }


    public XmlResourceParser loadXmlResourceParser( int id,  String type)
            throws NotFoundException {
        Log.e(TAG, "loadXmlResourceParser");
//        final TypedValue value = obtainTempTypedValue();
//        try {
//            final ResourcesImpl impl = mResourcesImpl;
//            impl.getValue(id, value, true);
//            if (value.type == TypedValue.TYPE_STRING) {
//                return impl.loadXmlResourceParser(value.string.toString(), id,
//                        value.assetCookie, type);
//            }
//            throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id)
//                    + " type #0x" + Integer.toHexString(value.type) + " is not valid");
//        } finally {
//            releaseTempTypedValue(value);
//        }
        return null;
    }

}
